import { defineStore } from 'pinia'
import { ref } from 'vue'
import persist from 'pinia-plugin-persistedstate'

// 用户模块 token setToken removeToken
export const useUserStore = defineStore(
  'big-user',
  () => {
    const token = ref('')
    const setToken = (newToken: string) => {
      token.value = newToken
    }

    const removeToken = () => {
      token.value = ''
    }

    const userId = ref()
    const setUserId = (newUserId: any) => {
      userId.value = newUserId
    }
    const getUserId = () => {
      return userId.value
    }

    const identify = ref()
    const setIdentify = (newIdentify: any) => {
      identify.value = newIdentify
    }

    const getIdentify = () => {
      return identify.value
    }

    const avatar = ref()
    const setAvatar = (newAvatar: any) => {
      avatar.value = newAvatar
    }
    const getAvatar = () => {
      return avatar.value
    }

    return {
      token,
      setToken,
      removeToken,
      identify,
      getIdentify,
      setIdentify,
      avatar,
      getAvatar,
      setAvatar,
      userId,
      setUserId,
      getUserId
    }
  },
  {
    persist: true
  }
)
